AC_INIT(Classe PDF, 1.0.0, alcione.sombra@gmail.com, libapdf, http://www.alcionesytes.net)
AC_PREREQ([2.50])
AC_CONFIG_AUX_DIR([.])
AM_INIT_AUTOMAKE([dist-xz 1.11 gnu -Wall -Wmultichar -Woverflow])
AC_CONFIG_MACRO_DIR([m4])
m4_pushdef([AC_INCLUDES_DEFAULT], [$1])
AC_COPYRIGHT([Alcione Ferreira])
AC_REVISION([$Revision: 1.0.0 $])

AC_CONFIG_HEADERS([src/configapdf.h])
#LT_INIT([static])
#LDFLAGS="-static-libgcc -static-libstdc++ -static $LDFLAGS"
#case "$host_os" in
#	mingw*)
#		LDFLAGS="$LDFLAGS /opt/lib/libcpmt.lib /opt/lib/msvcprt.lib"
#		;;
#esac
AC_PROG_CXX
AC_PROG_LD
AC_LANG([C++])
######################################################################
# DOXYGEN SUPPORT
######################################################################

DX_HTML_FEATURE(ON)
DX_CHM_FEATURE(OFF)
DX_CHI_FEATURE(OFF)
DX_MAN_FEATURE(OFF)
DX_RTF_FEATURE(OFF)
DX_XML_FEATURE(OFF)
DX_PDF_FEATURE(ON)
DX_PS_FEATURE(ON)

DX_INIT_DOXYGEN([$PACKAGE_NAME],[doxygen.cfg],[doc])

######################################################################
AM_PROG_LIBTOOL
AC_PREFIX_DEFAULT([/usr])

AC_SUBST([AM_CXXFLAGS])
AC_SUBST([AM_LDFLAGS])

AC_HEADER_STDC
AC_CHECK_HEADERS([iostream string fstream vector])
AC_CHECK_HEADERS([ctime cstdio cstdlib ctype.h ltdl.h dlfcn.h])
AC_SEARCH_LIBS([lt_dlopen], [ltdl])
AC_SEARCH_LIBS([dlopen], [dl])

STANDARD_PREFIXES="/usr /usr/local /opt /local /mingw /mingw32 /mingw64"

AC_ARG_WITH(libdir,
  [AS_HELP_STRING([--with-libdir],[look for libraries in .../NAME rather than .../lib])
  ],
  [LIBDIR=$with_libdir],
  [LIBDIR=lib]
)

# --with-zlib
AC_ARG_WITH(zlib,
  [AS_HELP_STRING([--with-zlib],[specify Zlib install prefix])
  ],
  [ ],
  [with_zlib=yes]
)

if test "x$with_zlib" = "xno"; then
  AC_DEFINE([HAVE_NOZLIB], [], [zlib is not available])
else
  AC_MSG_CHECKING([Zlib install prefix])

  if test "x$with_zlib" = "xyes"; then
    for i in `echo "$STANDARD_PREFIXES"`; do
      if test -f "$i/include/zlib.h"; then
        ZLIB_DIR="$i"
        break;
      fi
    done
  else
    if test -f "$with_zlib/include/zlib.h"; then
      ZLIB_DIR="$with_zlib"
      break;
    else
      AC_MSG_ERROR([Can't find Zlib headers under $with_zlib directory]);
    fi
  fi

  if test "x$ZLIB_DIR" = "x"; then
    AC_MSG_ERROR([Unable to locate Zlib headers, please use --with-zlib=<DIR>]);
  fi

  AC_MSG_RESULT([$ZLIB_DIR])
  LDFLAGS="$LDFLAGS -L$ZLIB_DIR/$LIBDIR"
  CFLAGS="$CFLAGS -I$ZLIB_DIR/include"
  LIBS="$LIBS -lz"
  ZLIBA="$ZLIB_DIR/$LIBDIR/libz.a"
  AC_SUBST([ZLIBA])

  AC_CHECK_LIB([z], [deflate], [], [
    AC_MSG_ERROR([deflate() is missing, check config.log for more details])
  ])

  HAVE_ZLIB=yes
fi
AC_SUBST([LIBHPDF_dir],['libhpdf'])
AC_SUBST([LIBHPDF_include],['-I$(top_srcdir)/libhpdf/include'])
if test "x$with_dinamico" = "xyes"; then
	AC_SUBST([LIBHPDF_libs],['$(top_srcdir)/libhpdf/src/libhpdf.a -lpng'])
else
	AC_SUBST([LIBHPDF_libs],['$(top_srcdir)/libhpdf/src/libhpdf.a $(ZLIBA) -lpng'])
fi

PKG_CHECK_MODULES([SSL], [openssl >= 0.9.8])

AC_SUBST([LIBEX_dir], ['libex'])
AC_SUBST([LIBEX_include], ['-I$(top_srcdir)/libex/src '])
AC_SUBST([LIBEX_libs], ['$(top_srcdir)/libex/src/libex-1.0.la '])

AC_SUBST([LIBAPDF_SO_VERSION], [1:0:0])
AC_SUBST([LIBAPDF_API_VERSION], [1.0])

AC_CONFIG_FILES([Makefile src/Makefile teste/Makefile libapdf-${LIBAPDF_API_VERSION}.pc:libapdf.pc.in])
#Definindo topo do config.h
AH_TOP([
#ifndef __CONFIGAPDF_H__
#define __CONFIGAPDF_H__ 1

#if  defined(__WIN32__) || defined(__WIN__)
#define NO_LINUX 1
#include <windows.h>
#endif
])

AH_BOTTOM([
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# ifdef HAVE_SYS_TIME_H
#  include <sys/time.h>
# else
#  include <time.h>
# endif
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# ifdef HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
#ifdef HAVE_STRING_H
# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
#  include <memory.h>
# endif
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_LIBM
# include <math.h>
#endif
#ifdef HAVE_IOSTREAM
# include <iostream>
#endif
#ifdef HAVE_STRING
# include <string>
#endif
#ifdef HAVE_FSTREAM
# include <fstream>
#endif
#ifdef HAVE_VECTOR
# include <vector>
#endif
#ifdef HAVE_MEMORY
# include <memory>
#endif
#ifdef HAVE_CTIME
# include <ctime>
#endif
#ifdef HAVE_CSTDIO
# include <cstdio>
#endif
#ifdef HAVE_CSTDLIB
# include <cstdlib>
#endif
#ifdef HAVE_CTYPE_H
# include <ctype.h>
#endif
#ifdef HAVE_LTDL_H
# include <ltdl.h>
#endif
#ifdef HAVE_DLFCN_H
# include <dlfcn.h>
#endif
#ifdef HAVE_LIBEX_H
# include <libex.h>
#endif

#if defined(__APPLE__)
#  define COMMON_DIGEST_FOR_OPENSSL
#  include <CommonCrypto/CommonDigest.h>
#  define SHA1 CC_SHA1
#else
#  include <openssl/md5.h>
#endif

#endif /*__CONFIGAPDF_H__*/
])

AC_CONFIG_SUBDIRS([libex libhpdf])

AC_OUTPUT
